<template lang="html">
  <div class="box">
      <div class="header">
          <el-form class="filterCondition demo-form-inline" :inline="true" label-width="80px">
              <el-input placeholder="输入车主姓名/联系方式" v-model="keyword" style="width: 420px;">
                <el-button slot="append" style="width: 120px;" @click="search()">搜索</el-button>
              </el-input>
          </el-form>
      </div>

      <div class="body">
          <el-table :data="tableData.list" style="width: 100%">
              <el-table-column label="车主姓名" prop="name" align="center" width=""></el-table-column>
              <el-table-column label="联系方式" prop="phone" align="center" width=""></el-table-column>
              <el-table-column label="邦保养卡号" align="center" width="">
                  <template slot-scope="scope">
                      <el-button type="primary" @click="viewDetail(1,scope.row)" plain size="mini">{{scope.row.card_number}}</el-button>
                  </template>
              </el-table-column>
              <el-table-column label="绑定维修厂" align="center" width="">
                  <template slot-scope="scope">
                      <el-button type="primary" @click="viewDetail(2,scope.row)" plain size="mini">{{scope.row.shop_name}}</el-button>
                  </template>
              </el-table-column>
              <el-table-column label="行驶里程" align="center" width="">
                  <template slot-scope="scope">
                      <el-button type="primary" @click="viewDetail(3,scope.row)" plain size="mini">查看详情</el-button>
                  </template>
              </el-table-column>
              <el-table-column label="设备号" prop="eq_num" align="center" width=""></el-table-column>
          </el-table>
      </div>

      <div class="page_box">
          <el-pagination class="page" layout="prev, pager, next"
            @current-change="switchPage" :current-page="currentPage" :page-count='tableData.rows' >
          </el-pagination>
      </div>

      <div class="">
          <el-dialog title="邦保养卡号详情" :visible.sync="dialogTableVisible1">
              <el-table :data="gridData">
                  <el-table-column align="center" property="card_price" label="卡金额"></el-table-column>
                  <el-table-column align="center" property="card_type" label="卡次数"></el-table-column>
                  <el-table-column align="center" property="remain_times" label="卡剩余次数"></el-table-column>
                  <el-table-column align="center" property="company" label="维修厂"></el-table-column>
                  <el-table-column align="center" property="sale_time" label="购卡时间"></el-table-column>
              </el-table>
          </el-dialog>
          <el-dialog title="绑定维修厂详情" :visible.sync="dialogTableVisible2">
              <el-table :data="gridData">
                  <el-table-column align="center" property="company" label="维修厂名称"></el-table-column>
                  <el-table-column align="center" property="leader" label="负责人"></el-table-column>
                  <el-table-column align="center" property="phone" label="电话"></el-table-column>
                  <el-table-column align="center" label="地址">
                    <template slot-scope="scope">
                      <p>{{scope.row.province}}-{{scope.row.city}}-{{scope.row.county}}-{{scope.row.address}}</p>
                    </template>
                  </el-table-column>
                  <el-table-column align="center" property="num" label="设备绑定数"></el-table-column>
                  <el-table-column align="center" property="audit_time" label="系统开通时间"></el-table-column>
              </el-table>
          </el-dialog>
          <el-dialog title="行驶里程详情" width="30%" :visible.sync="dialogTableVisible3">
              <el-table :data="gridData">
                  <el-table-column align="center" property="o_number" label="设备号"></el-table-column>
                  <el-table-column align="center" property="km" label="行驶里程"></el-table-column>
                  <el-table-column align="center" property="create_time" label="时间"></el-table-column>
              </el-table>
          </el-dialog>
      </div>

  </div>
</template>

<script>
export default {
  data(){
    return {
      keyword:'',
      tableData:[],
      dialogTableVisible1:false,
      dialogTableVisible2:false,
      dialogTableVisible3:false,
      currentPage:1,
      gridData:[]
    }
  },
  created(){
    this.bbyObdUser()
  },
  methods:{
    search(){
      this.bbyObdUser()
    },
    bbyObdUser(page=1){
      this.currentPage = page;
      this.$http4.bbyObdUser({
        key: this.keyword,
        page:page
      }).then(res=>{
        this.tableData =
        res.data.code == 1?
        res.data.data :[]
      })
    },
    viewDetail(n,e){
      this['dialogTableVisible'+n] = true;
      this.gridData = [];
      switch (n) {
        case 1:
          this.$http4.bbyObdCard({id:e.id}).then(res=>{
            this.gridData =
            res.data.code == 1?
            res.data.data.list :[]
          })
          break;
        case 2:
          this.$http4.bbyObdShop({sid:e.sid})
          .then(res=>{
            this.gridData =
            res.data.code == 1?
            res.data.data.list :[]
          })
          break;
        case 3:
          this.$http4.bbyObdKm({eq_num:e.eq_num})
          .then(res=>{
            this.gridData =
            res.data.code == 1?
            res.data.data.list :[]
          })
          break;
      }
    },
    switchPage(p){
      this.bbyObdUser(p)
    }
  }
}
</script>

<style lang="css" scoped>
@import "../../../my-style/app.css";
/deep/ .el-input-group__append, .el-input-group__prepend{
  background-color: #3498E9;
  border: none;
  color: white;
}
/deep/ .table_box .preview-img{
  display:block;
  width: 100%;
  height: 30px;
}
.page_box{
  text-align: center;
}
</style>
